# Make file for SciTE on Windows
# Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
# The License.txt file describes the conditions under which this software may be distributed.
# This makefile assumes the mingw32 version of GCC 3.2 or 4.x is used and changes will
# be needed to use other compilers.

.SUFFIXES: .cxx
CC = g++
DLLWRAP = dllwrap
ifndef CYGWIN
DEL = del /q
COPY = copy
else
DEL = rm
COPY = cp
endif

PROG	= ../bin/SciTE.exe
PROGSTATIC = ../bin/Sc1.exe
WIDEFLAGS=-DUNICODE -D_UNICODE

vpath %.h ../src ../../scintilla/include ../../scintilla/win32
vpath %.cxx ../src
vpath %.o ../../scintilla/win32
vpath %.a ../../scintilla/win32

ifndef NO_LUA
LUA_CORE_OBJS = lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
		lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o \
		ltable.o ltm.o lundump.o lvm.o lzio.o

LUA_LIB_OBJS =	lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o ltablib.o \
		lstrlib.o loadlib.o loslib.o linit.o

LUA_OBJS = LuaExtension.o SingleThreadExtension.o $(LUA_CORE_OBJS) $(LUA_LIB_OBJS)

vpath %.c ../lua/src ../lua/src/lib

LUA_INCLUDES = -I ../lua/include
#LUA_SCRIPTS = ..\bin\SciTEExtension.lua ..\bin\SciTEStartup.lua
else
LUA_DEFINES = -DNO_LUA
endif

INCLUDEDIRS=-I ../../scintilla/include -I ../../scintilla/win32 -I ../src $(LUA_INCLUDES)
RCINCLUDEDIRS=--include-dir ../../scintilla/win32 --include-dir ../src

CBASEFLAGS = -W -Wall $(INCLUDEDIRS) $(LUA_DEFINES) $(WIDEFLAGS) -mno-cygwin

ifdef DEBUG
CFLAGS=-DDEBUG -g $(CBASEFLAGS)
else
CFLAGS=-DNDEBUG -Os $(CBASEFLAGS)
STRIPFLAG="-Wl,-s"
endif

CXXFLAGS = $(CFLAGS) -Wno-char-subscripts -pedantic -fno-rtti -mno-cygwin

LDFLAGS=-mwindows -lcomctl32 -limm32 -lole32 -luuid $(LUA_LDFLAGS) -mno-cygwin

.cxx.o:
	$(CC) $(CXXFLAGS) -c $< -o $@

.c.o:
	gcc $(CFLAGS) -c $< -o $@

OTHER_OBJS	= FilePath.o SciTEBuffers.o SciTEIO.o Exporters.o PropSetFile.o StringList.o \
SciTEProps.o SciTEWin.o SciTEWinBar.o SciTEWinDlg.o MultiplexExtension.o \
StyleWriter.o UniqueInstance.o \
Utf8_16.o SciTERes.o GUIWin.o \
IFaceTable.o DirectorExtension.o JobQueue.o WinMutex.o $(LUA_OBJS)

OBJS = SciTEBase.o $(OTHER_OBJS)

DLLS=..\bin\Scintilla.dll ..\bin\SciLexer.dll

#++Autogenerated -- run scintilla/src/LexGen.py to regenerate
#**1:LEXPROPS=\\\n\(..\\bin\\\* \)
LEXPROPS=\
..\bin\abaqus.properties ..\bin\ada.properties ..\bin\asm.properties \
..\bin\asn1.properties ..\bin\au3.properties ..\bin\ave.properties \
..\bin\baan.properties ..\bin\blitzbasic.properties ..\bin\bullant.properties \
..\bin\caml.properties ..\bin\cmake.properties ..\bin\cobol.properties \
..\bin\conf.properties ..\bin\cpp.properties ..\bin\csound.properties \
..\bin\css.properties ..\bin\d.properties ..\bin\eiffel.properties \
..\bin\erlang.properties ..\bin\escript.properties ..\bin\flagship.properties \
..\bin\forth.properties ..\bin\fortran.properties ..\bin\freebasic.properties \
..\bin\gap.properties ..\bin\html.properties ..\bin\inno.properties \
..\bin\kix.properties ..\bin\latex.properties ..\bin\lisp.properties \
..\bin\lot.properties ..\bin\lout.properties ..\bin\lua.properties \
..\bin\matlab.properties ..\bin\metapost.properties ..\bin\mmixal.properties \
..\bin\nimrod.properties ..\bin\nncrontab.properties ..\bin\nsis.properties \
..\bin\opal.properties ..\bin\others.properties ..\bin\pascal.properties \
..\bin\perl.properties ..\bin\pov.properties ..\bin\powerpro.properties \
..\bin\powershell.properties ..\bin\ps.properties ..\bin\purebasic.properties \
..\bin\python.properties ..\bin\r.properties ..\bin\rebol.properties \
..\bin\ruby.properties ..\bin\scriptol.properties ..\bin\smalltalk.properties \
..\bin\sorcins.properties ..\bin\specman.properties ..\bin\spice.properties \
..\bin\sql.properties ..\bin\tacl.properties ..\bin\tal.properties \
..\bin\tcl.properties ..\bin\tex.properties ..\bin\vb.properties \
..\bin\verilog.properties ..\bin\vhdl.properties ..\bin\yaml.properties
#--Autogenerated -- end of automatically generated section

PROPS=..\bin\SciTEGlobal.properties ..\bin\abbrev.properties $(LEXPROPS)

ALL:	$(PROG) $(PROGSTATIC) $(DLLS) $(PROPS) $(LUA_SCRIPTS)

clean:
	$(DEL) *.exe *.o *.obj *.dll *.res *.map

deps:
	$(CC) -MM $(CXXFLAGS) *.cxx ../src/*.cxx ../lua/src/*.c ../lua/src/lib/*.c >deps.mak

..\bin\Scintilla.dll:	..\..\scintilla\bin\Scintilla.dll
	$(COPY) ..\..\scintilla\bin\Scintilla.dll $@

..\bin\SciLexer.dll:	..\..\scintilla\bin\SciLexer.dll
	$(COPY) ..\..\scintilla\bin\SciLexer.dll $@

..\bin\SciTEGlobal.properties:	..\src\SciTEGlobal.properties
	$(COPY) $^ $@
..\bin\abbrev.properties:	..\src\abbrev.properties
	$(COPY) $^ $@

#++Autogenerated -- run scintilla/src/LexGen.py to regenerate
#**1:\(..\\bin\\\*:\t..\\src\\\*\n\t$(COPY) $^ $@\n\)
..\bin\abaqus.properties:	..\src\abaqus.properties
	$(COPY) $^ $@
..\bin\ada.properties:	..\src\ada.properties
	$(COPY) $^ $@
..\bin\asm.properties:	..\src\asm.properties
	$(COPY) $^ $@
..\bin\asn1.properties:	..\src\asn1.properties
	$(COPY) $^ $@
..\bin\au3.properties:	..\src\au3.properties
	$(COPY) $^ $@
..\bin\ave.properties:	..\src\ave.properties
	$(COPY) $^ $@
..\bin\baan.properties:	..\src\baan.properties
	$(COPY) $^ $@
..\bin\blitzbasic.properties:	..\src\blitzbasic.properties
	$(COPY) $^ $@
..\bin\bullant.properties:	..\src\bullant.properties
	$(COPY) $^ $@
..\bin\caml.properties:	..\src\caml.properties
	$(COPY) $^ $@
..\bin\cmake.properties:	..\src\cmake.properties
	$(COPY) $^ $@
..\bin\cobol.properties:	..\src\cobol.properties
	$(COPY) $^ $@
..\bin\conf.properties:	..\src\conf.properties
	$(COPY) $^ $@
..\bin\cpp.properties:	..\src\cpp.properties
	$(COPY) $^ $@
..\bin\csound.properties:	..\src\csound.properties
	$(COPY) $^ $@
..\bin\css.properties:	..\src\css.properties
	$(COPY) $^ $@
..\bin\d.properties:	..\src\d.properties
	$(COPY) $^ $@
..\bin\eiffel.properties:	..\src\eiffel.properties
	$(COPY) $^ $@
..\bin\erlang.properties:	..\src\erlang.properties
	$(COPY) $^ $@
..\bin\escript.properties:	..\src\escript.properties
	$(COPY) $^ $@
..\bin\flagship.properties:	..\src\flagship.properties
	$(COPY) $^ $@
..\bin\forth.properties:	..\src\forth.properties
	$(COPY) $^ $@
..\bin\fortran.properties:	..\src\fortran.properties
	$(COPY) $^ $@
..\bin\freebasic.properties:	..\src\freebasic.properties
	$(COPY) $^ $@
..\bin\gap.properties:	..\src\gap.properties
	$(COPY) $^ $@
..\bin\html.properties:	..\src\html.properties
	$(COPY) $^ $@
..\bin\inno.properties:	..\src\inno.properties
	$(COPY) $^ $@
..\bin\kix.properties:	..\src\kix.properties
	$(COPY) $^ $@
..\bin\latex.properties:	..\src\latex.properties
	$(COPY) $^ $@
..\bin\lisp.properties:	..\src\lisp.properties
	$(COPY) $^ $@
..\bin\lot.properties:	..\src\lot.properties
	$(COPY) $^ $@
..\bin\lout.properties:	..\src\lout.properties
	$(COPY) $^ $@
..\bin\lua.properties:	..\src\lua.properties
	$(COPY) $^ $@
..\bin\matlab.properties:	..\src\matlab.properties
	$(COPY) $^ $@
..\bin\metapost.properties:	..\src\metapost.properties
	$(COPY) $^ $@
..\bin\mmixal.properties:	..\src\mmixal.properties
	$(COPY) $^ $@
..\bin\nimrod.properties:	..\src\nimrod.properties
	$(COPY) $^ $@
..\bin\nncrontab.properties:	..\src\nncrontab.properties
	$(COPY) $^ $@
..\bin\nsis.properties:	..\src\nsis.properties
	$(COPY) $^ $@
..\bin\opal.properties:	..\src\opal.properties
	$(COPY) $^ $@
..\bin\others.properties:	..\src\others.properties
	$(COPY) $^ $@
..\bin\pascal.properties:	..\src\pascal.properties
	$(COPY) $^ $@
..\bin\perl.properties:	..\src\perl.properties
	$(COPY) $^ $@
..\bin\pov.properties:	..\src\pov.properties
	$(COPY) $^ $@
..\bin\powerpro.properties:	..\src\powerpro.properties
	$(COPY) $^ $@
..\bin\powershell.properties:	..\src\powershell.properties
	$(COPY) $^ $@
..\bin\ps.properties:	..\src\ps.properties
	$(COPY) $^ $@
..\bin\purebasic.properties:	..\src\purebasic.properties
	$(COPY) $^ $@
..\bin\python.properties:	..\src\python.properties
	$(COPY) $^ $@
..\bin\r.properties:	..\src\r.properties
	$(COPY) $^ $@
..\bin\rebol.properties:	..\src\rebol.properties
	$(COPY) $^ $@
..\bin\ruby.properties:	..\src\ruby.properties
	$(COPY) $^ $@
..\bin\scriptol.properties:	..\src\scriptol.properties
	$(COPY) $^ $@
..\bin\smalltalk.properties:	..\src\smalltalk.properties
	$(COPY) $^ $@
..\bin\sorcins.properties:	..\src\sorcins.properties
	$(COPY) $^ $@
..\bin\specman.properties:	..\src\specman.properties
	$(COPY) $^ $@
..\bin\spice.properties:	..\src\spice.properties
	$(COPY) $^ $@
..\bin\sql.properties:	..\src\sql.properties
	$(COPY) $^ $@
..\bin\tacl.properties:	..\src\tacl.properties
	$(COPY) $^ $@
..\bin\tal.properties:	..\src\tal.properties
	$(COPY) $^ $@
..\bin\tcl.properties:	..\src\tcl.properties
	$(COPY) $^ $@
..\bin\tex.properties:	..\src\tex.properties
	$(COPY) $^ $@
..\bin\vb.properties:	..\src\vb.properties
	$(COPY) $^ $@
..\bin\verilog.properties:	..\src\verilog.properties
	$(COPY) $^ $@
..\bin\vhdl.properties:	..\src\vhdl.properties
	$(COPY) $^ $@
..\bin\yaml.properties:	..\src\yaml.properties
	$(COPY) $^ $@

#--Autogenerated -- end of automatically generated section

# Normally distributed rather than built as may not have grep on all machines
# Copy all non-comment lines from all the properties files into one combined file
..\src\Embedded.properties: $(PROPS)
	grep -v -h "^[#]" $(PROPS) >..\src\Embedded.properties

$(PROG): $(OBJS)
	$(CC) $(STRIPFLAG) -Xlinker --subsystem -Xlinker windows -o  $@ $^ $(LDFLAGS)

OBJSSTATIC = Sc1.o SciTEWinBar.o SciTEWinDlg.o MultiplexExtension.o \
	StyleWriter.o UniqueInstance.o SciTEBase.o FilePath.o SciTEBuffers.o \
	SciTEIO.o Exporters.o PropSetFile.o StringList.o SciTEProps.o ScintillaWinL.o \
	ScintillaBaseL.o Editor.o WindowAccessor.o DocumentAccessor.o KeyWords.o \
	ExternalLexer.o StyleContext.o Lexers.a PropSet.o RunStyles.o \
	ContractionState.o CharClassify.o Decoration.o Document.o CellBuffer.o CallTip.o Sc1Res.o PlatWin.o \
	PositionCache.o UniConversion.o Utf8_16.o GUIWin.o KeyMap.o Indicator.o LineMarker.o RESearch.o Selection.o Style.o \
	ViewStyle.o AutoComplete.o IFaceTable.o DirectorExtension.o MultiplexExtension.o XPM.o PerLine.o \
	JobQueue.o WinMutex.o $(LUA_OBJS)

$(PROGSTATIC): $(OBJSSTATIC)
	$(CC) $(STRIPFLAG) -Xlinker --subsystem -Xlinker windows -o $@ $^ $(LDFLAGS)

# Automatically generate dependencies for most files with "make deps"
include deps.mak

Sc1.o: SciTEWin.cxx SciTEWin.h SciTE.h Accessor.h WindowAccessor.h KeyWords.h PropSet.h \
 SString.h Scintilla.h Extender.h FilePath.h SciTEBase.h JobQueue.h
	$(CC) $(CXXFLAGS) -D STATIC_BUILD -c $< -o $@

SciTERes.o:	SciTERes.rc SciTE.h PlatformRes.h SciTE.exe.manifest
	windres $(RCINCLUDEDIRS) SciTERes.rc $@

# Also depends on ../src/Embedded.properties but may not want to build everywhere
# so must explicitly ask to build it.
Sc1Res.o:	SciTERes.rc SciTE.h PlatformRes.h SciTE.exe.manifest
	windres $(RCINCLUDEDIRS) SciTERes.rc --define STATIC_BUILD $@

# Make sure SciTEBase gets rebuilt (so its about box gets a new
# date stamp) when any of the other objects are updated.
SciTEBase.o: $(OTHER_OBJS)
